# -*- coding: utf-8 -*-
# file: db_handle.py
# @Author: zlw

import pymysql


class SchoolConnect:
    def __init__(self, ):
        self.conn = pymysql.connect(host='127.0.0.1',
                                    port=3306,
                                    user='root',
                                    password='155912',
                                    db='school')

        self.cursor = self.conn.cursor()

    def add_data(self):
        pass

    def delete_data(self):
        pass

    def select_data(self):
        pass

    def close_db(self):
        self.cursor.close()
        self.conn.close()


class UserdbConnect:
    def __init__(self):
        self.conn = pymysql.connect(host='127.0.0.1',
                                    port=3306,
                                    user='root',
                                    password='155912',
                                    db='userdb')
        self.username = None
        self.passwd = None
        self.cursor = self.conn.cursor()

    def add_data(self):
        self.cursor.execute(f"insert into users(username, password) values('{self.username}', '{self.passwd}')")
        self.conn.commit()

    def delete_data(self):
        pass

    def select_username(self):
        self.cursor.execute("select username from users where username = %s", (self.username,))

    def select_data(self):
        self.cursor.execute("select username, password from users where username = %s and password = %s",
                            (self.username, self.passwd))

    def close_db(self):
        self.cursor.close()
        self.conn.close()
